#include <iostream>
#include <algorithm>

using namespace std;

struct show
{
    int start;
    int end;
};

bool cmp(struct show a, struct show b)
{
        return a.end < b.end;
}

int main()
{
    ios::sync_with_stdio(false);
    int n; //想看的节目数量
    int max; //能看的最大节目数量
    int last; //能看的上一个节目的数组下标
    int i;
    struct show tvshows[110];
    while(true)
    {
        cin >> n;
        if(n == 0)
        {
            break;
        }
        for (i = 0; i < n;i++)
        {
            cin >> tvshows[i].start >> tvshows[i].end;
        }
        sort(tvshows, tvshows + n,cmp);
        last = 0;
        max = 0;
        for (i = 0; i < n;i++)
        {
            if(tvshows[i].start >= tvshows[last].end || i == 0)
            {
                max += 1;
                last = i;
            }
        }
        cout << max << endl;
    }
    return 0;
}